/*
	PlAr is Platform Arena: a 2D multiplayer shooting game
	Copyright (c) 2010, Antonio Ragagnin <spocchio@gmail.com>
	All rights reserved.

	This file is licensed under the New BSD License.
*/

package plar.core;

import java.util.HashMap;

/**
* ActionManager help to manage Action, containts and calls them.
*
* @author Antonio Ragagnin
*
*/
public class ActionManager {

	public HashMap<String, Action> actions;

	/** Element that handles this ActionManager
	*  ActionManager will pass it at EACH Action added.
	*/
	Element me;

	public ActionManager(Element m) {
		actions = new HashMap<String, Action>();
		me = m;
	}

	public Action addAction(String name, Action a) {
		actions.put(name, a);
		a.me=me;
		a.name=name;
		return a;
	}

	public Action getAction(String s) {
		return actions.get(s);
	}

	public boolean hasAction(String string) {
		return actions.containsKey(string);
	}

	public void removeAction(String s) {
		actions.remove(s);

	}

	public void removeAction(String s, Action a) {
		actions.remove(s);
	}


	public void runAll() {
		for (String s : actions.keySet()) {
			actions.get(s).run();
		}
	}

	public void forceAction(String string, Object object) {
		if(actions.containsKey(string)) actions.get(string).force(object);

	}

	public void clean() {
		actions.clear();

	}

}
